#include "lpc17xx_i2c.h"
#include "api_1wire.h"
#include "api_ibutton.h"

Status get_ibutton_sn(uint8_t* sn, uint64_t timeout)
{
	Status st;
	uint8_t i;
	if(lwire_take(IBUTTON,timeout))
	{
		if(lwire_write_byte(0x33)==ERROR)
		{	
			lwire_give();
			return ERROR;
		}
		for(i=0;i<8;i++)
			if(lwire_read_byte(sn+i)!=SUCCESS)
			{
				lwire_give();
				return ERROR;
			}
		lwire_give();					
 		return SUCCESS; 
	}
	return ERROR;
}